/*
 * Created by JFormDesigner on Sun Oct 19 20:19:34 CST 2025
 */

package com.geek.javase.ch10.jformdesigntest.japanel;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class MainPanel extends JPanel {
    private MyFrame my;

    public MainPanel(MyFrame my) {
        this.my = my;
        initComponents();
    }
    //点击返回按钮 跳转至登录界面
    private void backButtonActionPerformed(ActionEvent e) {
        // TODO add your code here
        //获取当前父级容器的布局管理器———>CardLayout
        CardLayout cardLayout = (CardLayout)this.getParent().getLayout();
        cardLayout.show(this.getParent(),"login");
        //清空当前主界面信息
        clearMain();
    }
    //清空主界面信息
    public void clearMain(){
        nameLabel.setText("");
        sexLabel.setText("");
    }

    //初始化界面
    public void initMain() {
        nameLabel.setText(my.user.getName());
        sexLabel.setText(my.user.getGender());
    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        titleLabel = new JLabel();
        backButton = new JButton();
        sexLabel = new JLabel();
        nameLabel = new JLabel();

        //======== this ========
        setLayout(null);

        //---- titleLabel ----
        titleLabel.setText(" \u4e3b \u754c \u9762");
        titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
        titleLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
        add(titleLabel);
        titleLabel.setBounds(120, 15, 140, 67);

        //---- backButton ----
        backButton.setText("\u8fd4\u56de");
        backButton.addActionListener(e -> backButtonActionPerformed(e));
        add(backButton);
        backButton.setBounds(new Rectangle(new Point(155, 210), backButton.getPreferredSize()));

        //---- sexLabel ----
        sexLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 14));
        sexLabel.setHorizontalAlignment(SwingConstants.CENTER);
        add(sexLabel);
        sexLabel.setBounds(145, 155, 115, 25);

        //---- nameLabel ----
        nameLabel.setHorizontalAlignment(SwingConstants.CENTER);
        nameLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 14));
        add(nameLabel);
        nameLabel.setBounds(145, 105, 115, 25);

        setPreferredSize(new Dimension(400, 300));
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JLabel titleLabel;
    private JButton backButton;
    private JLabel sexLabel;
    private JLabel nameLabel;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
